package lhc.alg.top100;

/**
 * description: https://leetcode.cn/problems/jump-game-ii/
 *  跳跃游戏2  贪心
 * author: hongchen.liao
 * date:  2022/8/20
 */
public class _45_Jump_Game_II {

    class Solution {
        public int jump(int[] nums) {
            int n = nums.length-1;
            int maxFar = 0, end = 0, jumps = 0;
            for(int i = 0; i < n; i++){
                maxFar = Math.max(maxFar, i + nums[i]);
                if(i == end){
                    end = maxFar;
                    jumps++;
                }
            }
            return jumps;
        }
    }

}
